package org.grapes.wine.api.client.param;

import java.util.HashMap;
import java.util.Map;

public enum GrapeParam implements CharSequence {
	USER("user"),
	SESSION_KEY("session_key"),
	EXPIRES("expires"),
	IN_PROFILE("profile"),
	TIME("time"),
	ADDED("added"),
	API_KEY("api_key");

	private static Map<String, GrapeParam> _lookupTable = new HashMap<String, GrapeParam>(
			GrapeParam.values().length);
	static {
		for (GrapeParam param : GrapeParam.values()) {
			_lookupTable.put(param.toString(), param);
		}
	}

	public static GrapeParam get(String key) {
		return isInNamespace(key) ? _lookupTable.get(key) : null;
	}

	public static boolean isInNamespace(String key) {
		return null != key;
	}

	private String _paramName;

	private GrapeParam() {
		this._paramName = "grape_sig";
	}

	private GrapeParam(String name) {
		this._paramName = "grape_sig_" + name;
	}

	public char charAt(int index) {
		return this._paramName.charAt(index);
	}

	public int length() {
		return this._paramName.length();
	}

	public CharSequence subSequence(int start, int end) {
		return this._paramName.subSequence(start, end);
	}

	public String toString() {
		return this._paramName;
	}
}
